<template>
  <div class="home-new">
    <Panel :title="'新鲜好物'" :subTitle="'新鲜出炉 品质靠谱'">
      <template #right>
        <XtxMore path="/"></XtxMore>
      </template>
      <div ref="target">
        
        <transition-group name="fade">
          <!-- 面板内容 -->
          <ul v-if="result.length" class="goods-list">
            <li v-for="item in result" :key="item.id">
              <RouterLink :to="`/product/${item.id}`">
                <img :src="item.picture" alt="" />
                <p class="name ellipsis">{{ item.name }}</p>
                <p class="price">&yen;{{ item.price }}</p>
              </RouterLink>
            </li>
          </ul>
          <!-- 骨架 -->
          <Homeskeleton bg="#f0f9f4" v-else />
        </transition-group>
      </div>
    </Panel>
  </div>
</template>

<script>
import { ref } from "vue";
import Panel from "./home-panel.vue";
import Homeskeleton from "./home-skeleton.vue";
import { findNew } from "@/api/home";
import { useLazyData } from "@/hooks/index";

export default {
  name: "homeNew",
  components: { Panel, Homeskeleton },
  setup(props) {
    /*const goods = ref([]); */
    // 监听对象 （是否进入可视区）

    // findNew().then((res) => {
    //   goods.value = res.result;
    // });
    const {result, target} = useLazyData(findNew)
    return { result, target };
  },
};
</script>

<style scoped lang="less">
// 嵌套语法 & 父级类名
.fade {
  &-leave {
    &-active {
      position: absolute;
      width: 100%;
      transition: opacity 0.5s 0.2s;
      z-index: 1;
    }
    &-to {
      opacity: 0;
    }
  }
}

.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    .hoverShadow();
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }
    .price {
      color: @priceColor;
    }
  }
}
</style>